import { Component, Fragment } from 'react';
import { connect } from 'dva';

import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import StandartTable from '../../components/StandardTable';

import { Divider, Button, Card, Dropdown, Menu, Icon, Form, Input, Modal, Popconfirm } from 'antd';

import styles from './orderList';
@connect(
    ({ orderlist: { orderlists }, loading }) => ({
       orderlists,
        loading: loading.effects['orderlist/query'],
        // adding: loading.effects['position/addPosition']
      }),
    //   dispatch => ({
    //     removePositions(pos_objs) {
    //       return dispatch({ type: 'position/removePositions', payload: pos_objs });
    //     },
    //     addPosition(params) {
    //       return dispatch({ type: 'position/addPosition', payload: params });
    //     },
    //   })
)
@Form.create()
class OrderList extends Component {
  state = {
    selectedRows: [],
    modalNewVisible: false,
  };

  handleSelectRow = rows => {
    this.setState({ selectedRows: rows });
  };

  handleDeleteOne = obj => {
    const { remove } = this.props;
    remove([obj]);
  };

  handleDeleteList = () => {
    const { selectedRows } = this.state;
    const { remove } = this.props;
    remove(selectedRows);
  };

  render() {
    const { selectedRows } = this.state;

    const columns = [
      {
        title: '编号',
        dataIndex: 'user_id',
      },
      {
        title: '名称',
        dataIndex: 'name',
      },
      {
        title: '内容',
        dataIndex: 'notes',
      },
      {
        title: '操作',
        render: (txt, row, idx) => (
          <Fragment>
            <Divider type="vertical" />
            <Popconfirm
              title="将删除所有记录"
              okText="删除"
              cancelText="取消"
              onConfirm={() => this.handleDeleteOne(row)}
            >
              <Button type="danger" size="small">
                删除
              </Button>
            </Popconfirm>
          </Fragment>
        ),
      },
    ];
    const menu = (
      <Menu onClick={this.handleMenuClick} selectedKeys={[]}>
        <Menu.Item key="remove">删除</Menu.Item>
      </Menu>
    );

    const { loading, form,  orderlists } = this.props;

   
   const tableData=orderlists.data?orderlists.data:null;
   console.log(tableData)
    const { modalNewVisible } = this.state;
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
    };
    return (
      <PageHeaderLayout title="订单浏览">
        <Card bordered={false}>
          <div className={styles.tableList}>
            <div className={styles.tableListOperator}>
              {selectedRows.length > 0 && (
                <span>
                  <Popconfirm
                    title="将删除所选记录"
                    okText="删除"
                    cancelText="取消"
                    onConfirm={this.handleDeleteList}
                  >
                    <Button loading={removing}>批量删除</Button>
                  </Popconfirm>
                </span>
              )}
            </div>
            <StandartTable
              rowKey="id"
              selectedRows={selectedRows}
              onSelectRow={this.handleSelectRow}
              loading={loading}
              data={{ list:tableData }}
              columns={columns}
              onChange={e => console.log(e)}
            />
          
          </div>
        </Card>
      </PageHeaderLayout>
    );
  }
}

export default OrderList;
